package cn.xjt.demo03;

/**
 * daemon守护线程会因为用户线程关闭而关闭，默认为用户线程
 * y
 * @author xujiangtao
 * @create 2020-08-01-10:36
 */
public class TestDaemon {
    public static void main(String[] args) {
        God god = new God();
        HandsomeYou handsomeyou = new HandsomeYou();
        Thread thread = new Thread(god);
        thread.setDaemon(true);         //上帝守护线程
        thread.start();
        new Thread(handsomeyou).start();
    }
}
class God implements Runnable{

    @Override
    public void run() {
        while (true)
        {
            System.out.println("上帝守护着你");
        }
    }
}
class HandsomeYou implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println("Hello world 你开心的活着");
        }
        System.out.println("======goodbye world========");
    }
}
